//
//  PlayViewController.m
//  clublbiza
//
//  Created by WANG TOM on 8/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PlayViewController.h"

@interface PlayViewController ()

@end

@implementation PlayViewController
@synthesize moviPlayer;
@synthesize playerWraperView;
@synthesize videoListOpener;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    [self.moviPlayer release];
    self.playerWraperView = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

- (void) play:(NSURL*)videoPath
{
    self.moviPlayer = [[[MPMoviePlayerController alloc] initWithContentURL:videoPath] autorelease];
     //self.moviPlayer .scalingMode=MPMovieScalingModeAspectFill;
     //self.moviPlayer .controlStyle = MPMovieControlStyleEmbedded;
    //self.moviPlayer .controlStyle = MPMovieControlModeVolumeOnly;
    
    
     self.moviPlayer.view.frame = self.view.frame;
    //    theMovie.userCanShowTransportControls=NO;
    
    // Register for the playback finished notification.
    /*
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myMovieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object: self.moviPlayer ];
    */
    self.moviPlayer.repeatMode = MPMovieRepeatModeOne;
    // Movie playback is asynchronous, so this method returns immediately.
    [ self.moviPlayer  play];
    
    [self.playerWraperView addSubview: self.moviPlayer .view];
}


// When the movie is done,release the controller.
- (void)myMovieFinishedCallback:(NSNotification*)aNotification
{
    /*
    MPMoviePlayerController* theMovie=[aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
    
    // Release the movie instance created in playMovieAtURL
    [theMovie.view removeFromSuperview];
    [theMovie release];
    
    [self.videoListOpener dismissModalViewControllerAnimated:NO];
     */
  
} 
- (IBAction)closeButtonClick:(id)sender
{
    [self.moviPlayer stop];
    [self.videoListOpener dismissModalViewControllerAnimated:NO];
}
@end
